﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SS2TC.Speech
{
    public class Noise
    {
        public byte[] Filter(byte[] stream)
        {
            byte[] data = new byte[stream.Length];

            int j = 0;
            for (int i = 0; i < stream.Length; i++)
            {
                if (!(stream[i] >= 120 && stream[i] <= 136))
                {
                    data[j] = stream[i];
                    j++;
                }
            }

            byte[] filtered = new byte[j + 1];

            Array.Copy(data, filtered, filtered.Length);

            return filtered;
        }

        public double[] SlidingGradient(byte[] stream)
        {
            List<double> gradients = new List<double>();

            for (int i = 1; i < stream.Length; i++)
            {
                double gradient = (stream[i] - stream[i - 1]) / 2;
                gradients.Add(gradient);
            }

            return gradients.ToArray();
        }

        public byte[] FilterDifferent(byte[] stream)
        {
            List<byte> different = new List<byte>();

            different.Add(stream[0]);

            for (int i = 1; i < stream.Length; i++)
            {
                if (stream[i] != stream[i - 1])
                {
                    different.Add(stream[i]);   
                }
            }

            return different.ToArray();
        }
    }
}
